// const peer = require("./peer-control");

// peer.on("add-stream", (strem) => {
//   play(strem);
// });

control.peer.on("add-stream", (strem) => {
  play(strem);
});

const video = document.getElementById("control-video");
function play(strem) {
  video.srcObject = strem;
  // 当元数据加载完成
  video.onloadedmetadata = () => {
    video.play();
  };
}

// 事件
window.onkeydown = (e) => {
  let data = {
    keyCode: e.keyCode,
    shift: e.shiftKey,
    ctrl: e.ctrlKey,
    alt: e.altKey,
    meta: e.metaKey,
    win: e.winKey, // windows键
  };
  control.peer.emit("robot", "key", data);
};

window.onmouseup = (e) => {
  // data:{clientX,clientY,screen:{width,heigth},video:{width,height}}
  let data = {
    clientX: e.clientX,
    clientY: e.clientY,
    video: {
      // 拿到真实宽高
      width: video.getBoundingClientRect().width,
      height: video.getBoundingClientRect().height,
    },
  };
  control.peer.emit("robot", "mouse", data);
};
